$(document).ready(function() {

    $('#canvasLeftWrapper #link-1, #canvasLeftWrapper #link-2, #canvasLeftWrapper #link-3, #canvasLeftWrapper #link-4, ')
        .each(function(index) {
        $(this).attr('rel', 'address:' + makeUrl('/' + $(this).attr('title').toLowerCase()));
    });

    $('a').click(function(e) {
        e.preventDefault();
    });

   $.address.init(function(event) {

   })
   .change(function(event) {
        deepLink = event.value.split('/?')[0];
        if (deepLink.substring(deepLink.length - 1, deepLink.length) == '/') {
            deepLink = deepLink.substring(0, deepLink.length - 1);
        }
        switch(deepLink) {
            case '/multiplayer/newgame':
                if (isMenuOpen()) {
                    closeMenu();
                    emptyLobby();
                }
                if (OurGame.newGameScreenContent == undefined) {
                    createNewGameScreen();
                } else {
                    $('#lobby').html(OurGame.newGameScreenContent);
                    if (OurGame.doNotShowSlider) {
                        $('.sliderWrapper').remove();
                    } else {
                        // slider has to be recreated to work
                        $('span').remove();
                        jQuery("#slider").slider({to:9, from:2, step:1, skin:"round_plastic", limits:false, dimension:'', onstatechange:function (value) {
                            sliderStateChanged(value);
                        }});
                    }
                    window.clearInterval(OurGame.lobbyInterval);
                }
                break;
            case '/multiplayer':
                if (isMenuOpen()) {
                    closeMenu();
                }
                startLobby();
                break;

            case '/lobby':
                if ($('#lobby .newGame').length > 0) {
                    window.clearInterval(OurGame.lobbyInterval);
                    removeLobby();
                    createLobby();
                }
                closeMenu();
                break;

            case '/profile':
                openMenu();
                profile();
                break;
            case '/rankings':
                openMenu();
                rankings();
                break;
            case '/help':
                openMenu();
                help();
                break;
            case '/about':
                openMenu();
                about();
                break;

            default:
                startLobby();
                break;
        }
   });
});